package com.fuhan.common.handler;

import com.fuhan.common.exception.CodeException;
import com.fuhan.common.exception.UserActionException;
import com.fuhan.common.restful.ResponseJSON;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @Author: Chao
 * @description:
 * @Date: 2021/1/28 15:27
 */
@ControllerAdvice
@ResponseBody
public class ControllerExceptionHandler {

    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    @ExceptionHandler(value = UserActionException.class)
    public ResponseJSON userActionHandler(UserActionException e){
        return new ResponseJSON(e.getExceptionType());
    }

    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    @ExceptionHandler(value = CodeException.class)
    public ResponseJSON codeHandler(CodeException e){
        return new ResponseJSON(e.getExceptionType());
    }
}
